library(covid19census)
library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
library(tidyr)
library(ggplot2)
library(broom)
library(psych)
Attaching package: ‘psych’
The following objects are masked from ‘package:ggplot2’:
%+%, alpha
library(stringr)
library(DataExplorer)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 methods overwritten by 'htmltools':
method from
print.html tools:rstudio
print.shiny.tag tools:rstudio
print.shiny.tag.list tools:rstudio
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
library(plotly)
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
theme_set(theme_bw())
t_us <- covid19census::getus_tests()
Data of tests up to 2020-04-23 successfully imported!
names(t_us)
[1] "date" "state" "abbr"
[4] "positive" "negative" "pending"
[7] "hospitalized_curr" "hospitalized_cumul" "icu_curr"
[10] "icu_cumul" "ventilator_curr" "ventilator_cumul"
[13] "recovered" "hash" "date_checked"
[16] "death" "fips" "death_increase"
[19] "hospitalized_increase" "negative_increase" "positive_increase"
[22] "total_test_increase"
t_us %>%
select(date, state, positive, negative, pending) %>%
pivot_longer(cols = c("positive", "negative", "pending"), names_to = "det_tests") %>%
ggplot(aes(date, log2(value), colour = det_tests)) +
geom_line() +
facet_wrap(vars(state)) +
scale_x_date(guide = guide_axis(check.overlap = TRUE, angle = 45)) +
theme(legend.position = "top",
legend.title = element_blank())
NA
NA
NA
WHO ratio positive/total to talk about reopening
t_us %>%
mutate(ratio_pos = positive/(positive + negative)) %>%
filter(date == max(date)) %>%
ggplot(aes(reorder(state, ratio_pos), ratio_pos)) +
geom_col() +
scale_x_discrete(guide = guide_axis(check.overlap = TRUE, angle = 90)) +
labs(x = NULL,
y = "positive/(positive + negative)",
title = "Probability of a positive test") +
theme(legend.position = "top",
legend.title = element_blank())
t_us %>%
select(date,
state,
hospitalized_curr,
hospitalized_cumul
# icu_curr,
# icu_cumul
) %>%
pivot_longer(
cols = c(
"hospitalized_curr",
"hospitalized_cumul"
# "icu_curr",
# "icu_cumul"
),
names_to = "det_tests"
) %>%
ggplot(aes(date, log2(value), colour = det_tests)) +
geom_line() +
facet_wrap(vars(state)) +
scale_x_date(guide = guide_axis(check.overlap = TRUE, angle = 45)) +
theme(legend.position = "top",
legend.title = element_blank())
Same states have hospitalized current but not hospitalized cumulative and vicevera ????
** Possible different meaning of variables depending on the state **
t_us %>%
select(date,
state,
# hospitalized_curr,
# hospitalized_cumul
# icu_curr,
# icu_cumul
"ventilator_curr",
"ventilator_cumul"
) %>%
pivot_longer(
cols = c(
# "hospitalized_curr",
# "hospitalized_cumul"
"ventilator_curr",
"ventilator_cumul"
),
names_to = "det_tests"
) %>%
ggplot(aes(date, log2(value), colour = det_tests)) +
geom_line() +
facet_wrap(vars(state)) +
scale_x_date(guide = guide_axis(check.overlap = TRUE, angle = 45)) +
theme(legend.position = "top",
legend.title = element_blank())
t_us %>%
select(date,
state,
# hospitalized_curr,
# hospitalized_cumul
icu_curr,
icu_cumul
) %>%
pivot_longer(
cols = c(
# "hospitalized_curr",
# "hospitalized_cumul"
"icu_curr",
"icu_cumul"
),
names_to = "det_tests"
) %>%
ggplot(aes(date, log2(value), colour = det_tests)) +
geom_line() +
facet_wrap(vars(state)) +
scale_x_date(guide = guide_axis(check.overlap = TRUE, angle = 45)) +
theme(legend.position = "top",
legend.title = element_blank())
Lets see some totals
ggplotly(
t_us %>%
filter(date == max(date)) %>%
select(-hash, -date_checked, -fips) %>%
pivot_longer(cols = positive:total_test_increase, names_to = "metric", values_to = "value") %>%
ggplot(aes(state, value)) +
geom_col() +
facet_wrap(vars(metric), scales = "free_y", ncol = 1) +
scale_x_discrete(guide = guide_axis( angle = 90)),
height = 2000,
width = 600
)
NA